//
//  MainViewController.m
//  DiscountClub
//
//  Created by Philip Chew on 28/2/12.
//  Copyright (c) 2012 articwind@gmail.com. All rights reserved.
//

#import "MainViewController.h"
#import "LoginViewController.h"
#import "EditCardController.h"
#import "EditCardDetailsController.h"
#import "ViewSavedCardsController.h"
#import "AddCardDetailState.h"
#import "ConfigHelper.h"

@implementation MainViewController

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	self.title = @"Main Menu";
    [self checkForLogin];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - View Events
- (IBAction)onClick_Add 
{
	AddCardDetailState *acds = [[AddCardDetailState alloc] init];	
	EditCardDetailsController *edcd = [[EditCardDetailsController alloc] initWithEditCardDetailState:acds];
	[self.navigationController pushViewController:edcd animated:YES];
	[acds release];
	[edcd release];
}

- (IBAction)onClick_Edit
{
	
}

- (IBAction)onClick_View
{
	
	
}

#pragma mark - Private Methods
- (void)checkForLogin
{
	NSString *loginKey = [[ConfigHelper sharedInstance] getAppSettingsValue:@"LOGIN_TOKEN"];
	
	if(loginKey.length <= 0) {
		LoginViewController *loginViewController = [[LoginViewController alloc] initWithNotification:@"MainViewController"];
		[self.navigationController pushViewController:loginViewController animated:YES];
		[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( loginSuccess ) name:@"MainViewController" object:nil];
		[loginViewController release];
	}
}

- (void)loginSuccess
{
	
}

@end
